 var path = require("path");
 var webpack = require('webpack');
 var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
 var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
 var CopyWebpackPlugin = require('copy-webpack-plugin');
 module.exports = {
     cache: true,
     entry: {
         'entry': './src/index.js',
         'v3demo': './v3_src/V3Demo.js',
         // 'test':'./v3_src/test/test.js'
     },
     target: 'web',
     output: {
         path: __dirname + '/bundle',
         publicPath: "http://localhost:621/bundle/", //'/bundle/',window.resourceBaseUrl
         filename: '[name].js',
         chunkFilename: "[name].min.js"
     },
     module: {
         rules: [{
             test: /\.js[x]?$/,
             exclude: /node_modules/,             
             loader: 'babel-loader?presets[]=es2015&presets[]=react&compact=false',
             query: {
                 cacheDirectory: true, //important for performance
                 plugins: ["transform-regenerator"],
                 presets: ["react", "es2015", "stage-0"]
             }
         }, {
             test: /\.less$/,
             // loader: "style-loader!css-loader!less-loader",
             // options: {
             //     minimize: true
             // }
             use: [{
                 loader: "style-loader",
                 options: {
                     minimize: true
                 }
             }, {
                 loader: "css-loader",
                 options: {
                     minimize: true
                 }
             }, {
                 loader: "less-loader",
                 options: {
                     minimize: true
                 }
             }]

         }, {
             test: /\.css$/,
             // loader: "style-loader!css-loader!less-loader",
             // options: {
             //     minimize: true
             // }
             use: [{
                 loader: "style-loader",
                 options: {
                     minimize: true
                 }
             }, {
                 loader: "css-loader",
                 options: {
                     minimize: true
                 }
             }]
         }, {
             test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
             loader: 'url-loader?limit=300000&name=[name]-[hash].[ext]'
         }, {
             test: /\.json$/,
             loader: 'json-loader'
         }]
     },
     plugins: [
         new webpack.DllReferencePlugin({
             context:path.resolve(__dirname, "client"),
             manifest: require("./dll/vendor-manifest.json")
         }),
         new webpack.DefinePlugin({
             'process.env': {
                 'NODE_ENV': JSON.stringify('production')
             }
         }),
         new CopyWebpackPlugin([

             // // {output}/to/file.txt 
             // { from: 'from/file.txt', to: 'to/file.txt' },

             // // {output}/to/directory/file.txt 
             // { from: 'from/file.txt', to: 'to/directory' },

             // // Copy directory contents to {output}/ 
             // { from: 'from/directory' },

             // // Copy directory contents to {output}/to/directory/ 
             // { from: 'from/directory', to: 'to/directory' },

             // Copy glob results to /absolute/path/ 
             {
                 from: 'bundle/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: 'css/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: 'less/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: 'images/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: '*.*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: 'src/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: 'v3_src/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: 'test/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }, {
                 from: 'testEs/**/*',
                 to: 'E:/publicJsCore/reactExample'
             }



         ]),
         //  new uglifyJsPlugin({
         //      output: {
         //         comments: false, // remove all comments
         //     },
         //     compress: {
         //         warnings: false
         //     }
         // }),
         new CommonsChunkPlugin(({
             name: "common.js",
             // (the commons chunk name)

             filename: "./common.js",
             // (the filename of the commons chunk)

             // minChunks: 3,
             // (Modules must be shared between 3 entries)

             // chunks: ["pageA", "pageB"],
             // (Only use these entries)
         }))

     ],
     resolve: {
        extensions: [".js", ".jsx"],
        modules: [path.resolve(__dirname, "client"), "node_modules"] 
    }

 };